//
//  MineViewController.m
//  Hui
//
//  Created by HawkingWang on 16/10/26.
//  Copyright © 2016年 Hui. All rights reserved.
//

#import "MineViewController.h"
#import "EditNameView.h"//修改姓名View
#import "PaymentMethodView.h"//充值View
#import "PickUpAddressViewController.h"//取货地址Controller
#import "RecruitDiliverymanViewController.h"//招募配送员Controller
#import "IncomeDetailViewController.h"//收入明细Controller
#import "WebViewController.h"//网页Controller

@interface MineViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
/**是否为配送员*/
@property (weak, nonatomic) IBOutlet UIView *deliveryView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *deliveryConstraint;//160.5****0
/**用户信息*/
@property (weak, nonatomic) IBOutlet UIButton *userIcon;
@property (weak, nonatomic) IBOutlet UILabel *userName;
@property (weak, nonatomic) IBOutlet UILabel *userIdentity;
@property (weak, nonatomic) IBOutlet UIView *identityView;
@property (weak, nonatomic) IBOutlet UILabel *userPhone;
/**账户*/
@property (weak, nonatomic) IBOutlet UILabel *money;
/**配送信息*/
@property (weak, nonatomic) IBOutlet UILabel *vehicles;
@property (weak, nonatomic) IBOutlet UILabel *income;


@end

@implementation MineViewController
{
    EditNameView *_editView;
    PaymentMethodView *_rechargeView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = APPCOLOR;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.hidden = NO;
    
    //设置导航栏
    [self setNav];
    [self setScrollView];
    
    //设置信息
    [self setInfo];
}
- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = NO;
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
- (void)setNav{
    //导航栏透明
    UIImage *image = [[UIImage alloc] init];
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    //去掉黑线
    self.navigationController.navigationBar.shadowImage = image;
    
    self.navigationItem.title = @"我的";
    UIButton *close = [UIButton buttonWithType:UIButtonTypeCustom];
    close.frame = CGRectMake(0, 0, 19, 44);
    [close addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    UIImageView *closeImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 13.5, 19, 19)];
    closeImage.image = [UIImage imageNamed:@"top-off"];
    [close addSubview:closeImage];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:close];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    _identityView.layer.masksToBounds = YES;
    _identityView.layer.cornerRadius = 2;
    _identityView.layer.borderColor = [UIColor whiteColor].CGColor;
    _identityView.layer.borderWidth = 0.5;
}
- (void)setScrollView{
    _scrollView.showsVerticalScrollIndicator = NO;
}
#pragma mark === 设置基本信息 ===
- (void)setInfo{
//    [_userIcon setImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>];
//    _userName.text =
//    _userIdentity.text =
//    _userPhone.text =
    
//    _money.text =
//    _vehicles.text = 
//    _income.text =
}

#pragma mark === 点击事件 ===
/**修改昵称*/
- (IBAction)editName:(id)sender {
    _editView = [[[NSBundle mainBundle] loadNibNamed:@"EditNameView" owner:nil options:nil] lastObject];
    _editView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    _editView.backgroundColor = RGBACOLOR(0, 0, 0, 0.5);
    _editView.heightConstraint.constant = 113.5 * SCREEN_HEIGHT / 667;
    _editView.nickName.text = _userName.text;
    [[UIApplication sharedApplication] .keyWindow addSubview:_editView];
    
    __weak __typeof__ (EditNameView *)weakView = _editView;
    __weak __typeof__ (self)weakSelf = self;
    _editView.editViewClick = ^(int num){
        switch (num) {
            case 0:
                [weakView removeFromSuperview];
                break;
            case 1:
                DLog(@"修改成功");
            {
                [weakView removeFromSuperview];
                weakSelf.userName.text = weakView.nickName.text;
                [SVProgressHUD showSuccessWithStatus:@"修改成功"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                });
            }
            default:
                break;
        }
    };
}
/**充值*/
- (IBAction)recharge:(id)sender {
    _rechargeView = [[[NSBundle mainBundle] loadNibNamed:@"PaymentMethodView" owner:nil options:nil] lastObject];
    _rechargeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    _rechargeView.backgroundColor = RGBACOLOR(0, 0, 0, 0.5);
    _rechargeView.heightConstraint.constant = 113.5 * SCREEN_HEIGHT / 667;
    [[UIApplication sharedApplication].keyWindow addSubview:_rechargeView];
    
    __weak __typeof__ (PaymentMethodView *)weakView = _rechargeView;
    _rechargeView.paymentViewClick = ^(int num){
        switch (num) {
            case 0:
                [weakView removeFromSuperview];
                break;
            case 1:
                DLog(@"充值成功, 刷新");
            {
                [weakView removeFromSuperview];
                [SVProgressHUD showSuccessWithStatus:@"充值成功"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                });
            }
                break;
            default:
                break;
        }
    };
}
/**取货地址*/
- (IBAction)address:(id)sender {
    PickUpAddressViewController *pickUp = [[PickUpAddressViewController alloc] init];
    [self.navigationController pushViewController:pickUp animated:YES];
}
/**配送收入*/
- (IBAction)income:(id)sender {
    IncomeDetailViewController *income = [[IncomeDetailViewController alloc] init];
    [self.navigationController pushViewController:income animated:YES];
}
/**是否接单*/
- (IBAction)ifGetOrder:(id)sender {
}
/**招募配送员*/
- (IBAction)recruitDiliveryman:(id)sender {
    RecruitDiliverymanViewController *recruit = [[RecruitDiliverymanViewController alloc] init];
    [self.navigationController pushViewController:recruit animated:YES];
}
/**配送说明*/
- (IBAction)deliveryNotes:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"配送说明";
    [self presentViewController:web animated:YES completion:nil];
}
/**配送考试*/
- (IBAction)deliveryTest:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"配送考试";
    [self presentViewController:web animated:YES completion:nil];
}
/**客服中心*/
- (IBAction)service:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"客服中心";
    [self presentViewController:web animated:YES completion:nil];
}
/**用户指南*/
- (IBAction)guide:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"用户指南";
    [self presentViewController:web animated:YES completion:nil];
}
/**关于我们*/
- (IBAction)about:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"关于我们";
    [self presentViewController:web animated:YES completion:nil];
}
/**法律条款*/
- (IBAction)legal:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"法律条款";
    [self presentViewController:web animated:YES completion:nil];
}




- (void)close{
    [self.navigationController popViewControllerAnimated:NO];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
